using System;
using System.Xml.Serialization;

namespace Jaws.Core.Web.Entities.Profiles
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    [XmlDataDirectory("profiles")]
    public class Profile : XmlBusinessBase<Profile>
    {
        private ProfilePropertyCollection _inner;
        private string _username;
        private bool _anonymous;
        private DateTime _lastActivity;
        private DateTime _lastUpdates;

        /// <summary>
        /// Initializes a new instance of the <see cref="Profile"/> class.
        /// </summary>
        public Profile()
        {
            _inner = new ProfilePropertyCollection();
        }

        /// <summary>
        /// Gets or sets the name of the user.
        /// </summary>
        /// <value>The name of the user.</value>
        [XmlAttribute("username")]
        public string UserName
        {
            get { return _username; }
            set { _username = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is anonymous.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is anonymous; otherwise, <c>false</c>.
        /// </value>
        [XmlAttribute("anonymous")]
        public bool IsAnonymous
        {
            get { return _anonymous; }
            set { _anonymous = value; }
        }

        /// <summary>
        /// Gets or sets the last activity date.
        /// </summary>
        /// <value>The last activity date.</value>
        [XmlAttribute("lastActivity")]
        public DateTime LastActivityDate
        {
            get { return _lastActivity; }
            set { _lastActivity = value; }
        }

        /// <summary>
        /// Gets or sets the last updated date.
        /// </summary>
        /// <value>The last updated date.</value>
        [XmlAttribute("lastUpdated")]
        public DateTime LastUpdatedDate
        {
            get { return _lastUpdates; }
            set { _lastUpdates = value; }
        }

        /// <summary>
        /// Gets the properties.
        /// </summary>
        /// <value>The properties.</value>
        [XmlElement("property")]
        public ProfilePropertyCollection Properties
        {
            get { return _inner; }
        }

        /// <summary>
        /// Gets the size.
        /// </summary>
        /// <value>The size.</value>
        [XmlIgnore]
        public int Size
        {
            get { return _inner.Count; }
        }

        /// <summary>
        /// Creates the profile info.
        /// </summary>
        /// <returns></returns>
        public System.Web.Profile.ProfileInfo CreateProfileInfo()
        {
            return new System.Web.Profile.ProfileInfo(_username, _anonymous, _lastActivity, _lastUpdates, Size);
        }

    }
}